<template>
    <el-card>
        <el-form :inline="true">
            <el-form-item label="一级分类">
                <!-- change:选中值发生变化时触发 -->
                <el-select :disabled="scene==0?false:true" v-model="categoryStore.c1Id" @change="handler">
                    <el-option v-for="(c1, _index) in categoryStore.c1Arr" :key="c1.id" :label="c1.name"
                        :value="c1.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="二级分类">
                <el-select :disabled="scene==0?false:true" v-model="categoryStore.c2Id" @change="handler1">
                    <el-option v-for="(c2, _index) in categoryStore.c2Arr" :key="c2.id" :label="c2.name"
                        :value="c2.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="三级分类">
                <el-select :disabled="scene==0?false:true" v-model="categoryStore.c3Id">
                    <el-option v-for="(c3, _index) in categoryStore.c3Arr" :key="c3.id" :label='c3.name'
                        :value="c3.id"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
    </el-card>
</template>

<script setup lang="ts">
//挂载完毕
import { onMounted } from 'vue';
import useCategoryStore from '@/store/modules/category';
let categoryStore = useCategoryStore();

onMounted(() => {
    getC1();
});
//从仓库获取一级分类
const getC1 = () => {
    categoryStore.getC1();
}

//一级分类下拉菜单选中值的时候触发
const handler = () => {
    //将二级、三级分类的数据清空
    categoryStore.c2Id = '';
    categoryStore.c3Arr = [];
    categoryStore.c3Id = '';
    //并从仓库获取二级分类的数据
    categoryStore.getC2();
}
//二级分类下拉菜单事件选中值的时候触发
const handler1 = () => {
    //清理三级分类的数据
    categoryStore.c3Id = '';
    categoryStore.getC3();
}

//接收父组件的传值
defineProps(['scene'])

</script>

<style scoped></style>